#include"include/trackplayer.h"
#include<QtCore/QFileInfo>
TrackPlayer::TrackPlayer(QObject *parent):QObject(parent)
{
    audioOutput=new Phonon::AudioOutput(Phonon::MusicCategory,parent);
    mediaObject=new Phonon::MediaObject();
    mediaObject->setTickInterval(1000);
    Phonon::createPath(mediaObject,audioOutput);
    creatConnections();
}

void TrackPlayer::creatConnections()
{
}

void TrackPlayer::enqueue(const QString &fileName)
{
    mediaObject->enqueue(Phonon::MediaSource(fileName));
    //    if(mediaObject->state()!=Phonon::PlayingState)
    //        mediaObject->play();
}

void TrackPlayer::playTrack(const QString &fileName)
{
    mediaObject->clear();
    mediaObject->setCurrentSource(Phonon::MediaSource(fileName));
    mediaObject->play();
}

Phonon::MediaObject* TrackPlayer::getMediaObject()
{
    return mediaObject;
}

Phonon::AudioOutput* TrackPlayer::getAudioOutput()
{
    return audioOutput;
}

void TrackPlayer::playOrPause(bool b)
{
    //    Phonon::MediaSource s=mediaObject->currentSource();
    //    if(s.type()==Phonon::MediaSource::Empty)
    //        mediaObject->setCurrentSource(Phonon::MediaSource(trackName));
    if(b)
        mediaObject->play();
    else
        mediaObject->pause();
}

void TrackPlayer::stop()
{
    mediaObject->stop();
}

QString TrackPlayer::currentTackName()
{
    return (mediaObject->currentSource()).fileName();
}

Phonon::State TrackPlayer::state()
{
    return mediaObject->state();
}
